using System;
using System.Collections;
using System.Data;
using CE.Database;
/// <summary>
/// Summary description for UserProfileDB
/// </summary>
/// 
namespace CE.Provider
{
    public class CarClaimExpCoverTypeDB
    {
        public CarClaimExpCoverTypeDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public Int64 Insert(CarClaimExpCoverType carclaimexp)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "[sprocProviderCarClaimExpCoverTypeInsertUpdateSingleItem]";
            
            SortedList _sPara = new SortedList();
            
            #region Parameter
            _sPara.Add("@ProviderCarClaimExpCoverTypeId", carclaimexp.ProviderCarClaimExpCoverTypeId);
            _sPara.Add("@ProviderCompanyId", carclaimexp.ProviderCompanyId);
            _sPara.Add("@CXCoverTypeId", carclaimexp.CXCoverTypeId);
            _sPara.Add("@ProviderCarClaimExpId", carclaimexp.ProviderCarClaimExpId);
            _sPara.Add("@ClaimRate", carclaimexp.ClaimRate);
            _sPara.Add("@RefCEUserId", carclaimexp.RefCEUserId);
            _sPara.Add("@Status", carclaimexp.Status);
            _sPara.Add("@Finfo1", carclaimexp.FInfo1);
            _sPara.Add("@Dinfo1", carclaimexp.DInfo1);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public bool Update()
        {
            return true;
        }

        public bool Delete(Int64 ProviderCarClaimExpCoverTypeId, Int64 ProviderCompanyId)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "[sprocProviderCarClaimExpCoverTypeDeleteSingleItem]";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@ProviderCarClaimExpCoverTypeId", ProviderCarClaimExpCoverTypeId);
            _sPara.Add("@ProviderCompanyId", ProviderCompanyId);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result > 0;
        }

        public CarClaimExpCoverTypeList GetProviderCarClaimExpCoverTypeList(Int64 ProviderCompanyId)
        {
            CarClaimExpCoverTypeList _vehicleyearlist = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderCarClaimExpCoverTypeSelectItemList";

            SortedList _spara = new SortedList();
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _vehicleyearlist = new CarClaimExpCoverTypeList();
                    for (int i = 0; i < _dt.Rows.Count; i++)
                    {
                        CarClaimExpCoverType _vehicleyear = new CarClaimExpCoverType();
                        _vehicleyear = FillDataRecord(_dt, i);
                        _vehicleyearlist.Add(_vehicleyear);
                    }
                }
            }
            return _vehicleyearlist;
        }


        public CarClaimExpCoverType GetProviderCarClaimExpCoverType(Int64 ProviderCompanyId, Int32 CXCoverTypeId)
        {
            CarClaimExpCoverType _vehicleyear = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderCarClaimExpCoverTypeSelectSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);
            _spara.Add("@CXCoverTypeId", CXCoverTypeId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _vehicleyear = new CarClaimExpCoverType();
                    _vehicleyear = FillDataRecord(_dt, 0);
                }
            }
            return _vehicleyear;
        }

        public CarClaimExpCoverType GetProviderCarClaimExpCoverType(Int64 ProviderCompanyId, Int32 CXCoverTypeId, Int64 ProviderClaimExpInfoId)
        {
            CarClaimExpCoverType _claimcover = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderCarClaimExpCoverTypeSelectSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);
            _spara.Add("@CXCoverTypeId", CXCoverTypeId);
            _spara.Add("@ProviderCarClaimExpId", ProviderClaimExpInfoId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _claimcover = new CarClaimExpCoverType();
                    _claimcover = FillDataRecord(_dt, 0);
                }
            }

            return _claimcover;
        }

        public bool CheckProviderCarClaimExpCoverTypeDuplicate(Int64 CurrentProviderCliamExpCoverTypeId, Int64 ProviderCompanyId, Int32 CXCoverTypeId, Int64 ProviderClaimExpInfoId)
        {
            bool _retValue = false;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderCarClaimExpCoverTypeDuplicateSelectSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@ProviderCarClaimExpCoverTypeId", CurrentProviderCliamExpCoverTypeId);
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);
            _spara.Add("@CXCoverTypeId", CXCoverTypeId);
            _spara.Add("@ProviderCarClaimExpId", ProviderClaimExpInfoId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _retValue = true;
                }
            }

            return _retValue;
        }

        public CarClaimExpCoverType GetProviderCarClaimExpCoverType(Int64 ProviderCarClaimExpCoverTypeId)
        {
            CarClaimExpCoverType _vehicleyear = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderCarClaimExpCoverTypeSelectSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@CarClaimExpCoverTypeId", ProviderCarClaimExpCoverTypeId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _vehicleyear = new CarClaimExpCoverType();
                    _vehicleyear = FillDataRecord(_dt, 0);
                }
            }
            return _vehicleyear;
        }




        private CarClaimExpCoverType FillDataRecord(DataTable myDataTable, int RowId)
        {
            CarClaimExpCoverType myCarClaimExpCoverType = new CarClaimExpCoverType();
            myCarClaimExpCoverType.ProviderCarClaimExpCoverTypeId = Convert.ToInt64(myDataTable.Rows[RowId]["ProviderCarClaimExpCoverTypeId"].ToString());
            myCarClaimExpCoverType.ProviderCompanyId = Convert.ToInt64(myDataTable.Rows[RowId]["ProviderCompanyId"].ToString());
            myCarClaimExpCoverType.ProviderCarClaimExpId = Convert.ToInt32(myDataTable.Rows[RowId]["ProviderCarClaimExpId"].ToString());
            myCarClaimExpCoverType.CXCoverTypeId = Convert.ToInt32(myDataTable.Rows[RowId]["CXCoverTypeId"].ToString());
            myCarClaimExpCoverType.ClaimRate = Convert.ToSingle(myDataTable.Rows[RowId]["ClaimRate"].ToString());
            myCarClaimExpCoverType.RefCEUserId = Convert.ToInt64(myDataTable.Rows[RowId]["RefCEUserId"].ToString());
            myCarClaimExpCoverType.Status = Convert.ToBoolean(myDataTable.Rows[RowId]["Status"].ToString());

            if (myDataTable.Rows[RowId]["FInfo1"].ToString() != "")
                myCarClaimExpCoverType.FInfo1 = Convert.ToSingle(myDataTable.Rows[RowId]["FInfo1"].ToString());

            if (myDataTable.Rows[RowId]["DInfo1"].ToString() != "")
                myCarClaimExpCoverType.DInfo1 = Convert.ToDateTime(myDataTable.Rows[RowId]["DInfo1"].ToString());
            else
                myCarClaimExpCoverType.DInfo1 = Convert.ToDateTime(myDataTable.Rows[RowId]["ModifiedDate"].ToString());
            return myCarClaimExpCoverType;
        }
        
    }
}